package app;

import app.controller.http.HttpController;
import com.jfinal.kit.Kv;
import com.jfinal.template.Engine;
import com.jfinal.template.Template;
import org.ricks.agent.Agent;
import org.ricks.common.conf.NetWorkConfig;
import org.ricks.ioc.*;
import org.ricks.log.Logger;
import org.ricks.net.http.*;

import java.io.ByteArrayOutputStream;
import java.io.StringWriter;

@Agent
public class AppMain {

	public static void main(String[] args) throws Exception {
		NetWorkConfig.setPort(8888); //如果配置服务器端口，可以不写
//		AppContext.setBannerMode(Banner.Mode.OFF); //设置banner 是否开启，默认开启
		AppContext.run(AppMain.class);//启动容器 & 启动server
		RestfulBootstrap restfulBootstrap = RestfulBootstrap.getInstance();
		restfulBootstrap.controller(HttpController.class);
		restfulBootstrap.start();
//		HttpBootstrap httpBootstrap = new HttpBootstrap();
//		httpBootstrap.httpHandler(new HttpStaticResourceHandler("static"));
//		httpBootstrap.start();
//
//		Engine engine = Engine.use();
//
//		engine.setDevMode(true);
//		engine.setToClassPathSourceFactory();
//
//		engine.getTemplate("index.html");
//
//		Kv kv = Kv.by("key", 123);
//		Template template = engine.getTemplate("index.html");
//
//		// 字节流模式输出到 OutputStream
//		ByteArrayOutputStream baos = new ByteArrayOutputStream();
//		template.render(kv, baos);
//
//		// 字符流模式输出到 StringWriter
//		StringWriter sw = new StringWriter();
//		template.render(kv, sw);
//
//		// 直接输出到 String 变量
//		String str = template.renderToString(kv);
//		System.err.println(str);

		long s = System.currentTimeMillis();

		for (int i = 0; i < 10000000; i++) {
			Logger.info(" ricks is demon ");
		}
		long e = System.currentTimeMillis();
		Logger.info(" time: {}" ,(e-s));
	}

}
